package org.javaapps.common.util;

import java.util.Enumeration;

import javax.servlet.http.HttpServletRequest;

public class URLHelper {
	public static String requestRelayString(HttpServletRequest request) {
		String url = request.getRequestURI();
		Enumeration<?> e = request.getParameterNames();
		while (e.hasMoreElements()) {
			String param = (String) e.nextElement();
			String[] values = request.getParameterValues(param);
			for (int i = 0; i < values.length; i++) {
				if (i == 0)
					url += "?" + param + "=" + values[i];
				else
					url += "&" + param + "=" + values[i];
			}
		}
		return url;
	}
	
	public static String getJSPForwordPath(HttpServletRequest request){
		String url = request.getRequestURI();
		String context = request.getContextPath();
		url = url.substring(0, url.length() - 4);
		url = url.substring(url.indexOf(context) + context.length());
		System.out.println(url);
		return "JSP" + url;
	}
}
